package org.batyrov.equery.action.admin;

import org.batyrov.equery.action.BaseAction;
import org.batyrov.equery.action.Const;
import org.batyrov.equery.bean.User;
import org.batyrov.equery.bean.Window;

import java.util.Collection;

/**
 * Created by IntelliJ IDEA.
 * User: admin
 * Date: 25.07.2009
 * Time: 0:02:46
 * To change this template use File | Settings | File Templates.
 */
public class RemoveWindow  extends BaseAction {
    private long id;
    private Collection<Window> windows;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Collection<Window> getWindows() {
        return windows;
    }

    public void setWindows(Collection<Window> windows) {
        this.windows = windows;
    }

    @Override
    public String execute() throws Exception {
        super.execute();
        Window window = em.find(Window.class, id);
        if (window == null){
            addActionError(getText("window_not_found"));
            windows = dao.getAllWindow();
            return Const.ERROR;
        }
        if (!dao.remove(window)) {
            addActionError(getText("cannot_delete_window"));
            windows = dao.getAllWindow();
            return Const.ERROR;
        }
        return Const.SUCCESS;
    }
}
